package com.learning.platform.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ApiResponse<T> {
    private int code;
    private String message;
    private T data;
    @JsonProperty("traceId")
    private String traceId;
    
    public ApiResponse() {}
    
    public ApiResponse(int code, String message, T data, String traceId) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.traceId = traceId;
    }
    
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(0, "success", data, generateTraceId());
    }
    
    public static <T> ApiResponse<T> success(T data, String message) {
        return new ApiResponse<>(0, message, data, generateTraceId());
    }
    
    public static <T> ApiResponse<T> error(int code, String message) {
        return new ApiResponse<>(code, message, null, generateTraceId());
    }
    
    private static String generateTraceId() {
        return "trace-" + System.currentTimeMillis();
    }
    
    // Getters and Setters
    public int getCode() {
        return code;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public T getData() {
        return data;
    }
    
    public void setData(T data) {
        this.data = data;
    }
    
    public String getTraceId() {
        return traceId;
    }
    
    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }
}










